This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(ggplot2)
library(reshape)
library(reshape2)
##
## Attachement du package : 'reshape2'
## Les objets suivants sont masqués depuis 'package:reshape':
##
## colsplit, melt, recast
library(gridExtra)
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(FactoMineR)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.1 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::combine() masks gridExtra::combine()
## ✖ tidyr::expand() masks reshape::expand()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ dplyr::rename() masks reshape::rename()
## ✖ lubridate::stamp() masks reshape::stamp()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(cluster)
library(boot)
library(nortest)
library(corrplot)
## corrplot 0.92 loaded
library(ggmap)
## ℹ Google's Terms of Service: <https://mapsplatform.google.com>
## Stadia Maps' Terms of Service: <https://stadiamaps.com/terms-of-service/>
## OpenStreetMap's Tile Usage Policy: <https://operations.osmfoundation.org/policies/tiles/>
## ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
library(caret)
## Le chargement a nécessité le package : lattice
##
## Attachement du package : 'lattice'
##
## L'objet suivant est masqué depuis 'package:boot':
##
## melanoma
##
##
## Attachement du package : 'caret'
##
## L'objet suivant est masqué depuis 'package:purrr':
##
## lift
library(clue)
library(NbClust)
library(mclust)
## Package 'mclust' version 6.1
## Type 'citation("mclust")' for citing this R package in publications.
##
## Attachement du package : 'mclust'
##
## L'objet suivant est masqué depuis 'package:purrr':
##
## map
load("velib.RData")
summary(velib)
## Length Class Mode
## data 181 data.frame list
## position 2 data.frame list
## dates 181 -none- character
## bonus 1189 -none- numeric
## names 1189 -none- character
#Préparation des données
loading = as.matrix(velib$data)
colnames(loading) = 1:ncol(loading)
rownames(loading) = velib$names
#coord = read.csv("velibCoord.csv")
#coord = as.matrix(coord)
stations = 1:nrow(loading)
coord = velib$position[stations,]
coord$bonus = velib$bonus[stations] # 1 = sur une colline, 0 = non
dates = 14:181
loading=loading[stations, dates]
head(loading)
## 14 15 16 17 18
## EURYALE DEHAYNIN 0.03846154 0.03846154 0.07692308 0.03846154 0.03846154
## LEMERCIER 0.47826087 0.47826087 0.47826087 0.43478261 0.43478261
## MEZIERES RENNES 0.21818182 0.14545455 0.12727273 0.10909091 0.10909091
## FARMAN 0.95238095 0.95238095 0.95238095 0.95238095 0.95238095
## QUAI DE LA RAPEE 0.92753623 0.81159420 0.73913043 0.72463768 0.72463768
## CHOISY POINT D'IVRY 0.16666667 0.16666667 0.16666667 0.16666667 0.16666667
## 19 20 21 22 23
## EURYALE DEHAYNIN 0.03846154 0.03846154 0.03846154 0.10714286 0.00000000
## LEMERCIER 0.43478261 0.43478261 0.43478261 0.26086957 0.04347826
## MEZIERES RENNES 0.10909091 0.09090909 0.09090909 0.05454545 0.10909091
## FARMAN 0.95238095 0.95238095 1.00000000 1.00000000 1.00000000
## QUAI DE LA RAPEE 0.72463768 0.72463768 0.72463768 0.75362319 0.97101449
## CHOISY POINT D'IVRY 0.16666667 0.16666667 0.16666667 0.08333333 0.00000000
## 24 25 26 27 28
## EURYALE DEHAYNIN 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
## LEMERCIER 0.13043478 0.08695652 0.08695652 0.04347826 0.08695652
## MEZIERES RENNES 0.25454545 0.36363636 0.38181818 0.17021277 0.36956522
## FARMAN 1.00000000 0.95238095 1.00000000 1.00000000 1.00000000
## QUAI DE LA RAPEE 1.00000000 1.00000000 0.93333333 0.84444444 0.90000000
## CHOISY POINT D'IVRY 0.04166667 0.00000000 0.00000000 0.16666667 0.20833333
## 29 30 31 32 33
## EURYALE DEHAYNIN 0.00000000 0.03571429 0.10714286 0.10714286 0.2500000
## LEMERCIER 0.04347826 0.00000000 0.04347826 0.04347826 0.1304348
## MEZIERES RENNES 0.47826087 0.45652174 0.50000000 0.52173913 0.4782609
## FARMAN 1.00000000 1.00000000 0.95238095 0.14285714 0.0952381
## QUAI DE LA RAPEE 0.92452830 0.92452830 0.79245283 0.58490566 0.4230769
## CHOISY POINT D'IVRY 0.25000000 0.00000000 0.04166667 0.04166667 0.2500000
## 34 35 36 37 38
## EURYALE DEHAYNIN 0.3928571 0.4285714 0.5000000 0.39285714 0.39285714
## LEMERCIER 0.7826087 0.9130435 1.0000000 0.91304348 1.00000000
## MEZIERES RENNES 0.4130435 0.3478261 0.3913043 0.28260870 0.28260870
## FARMAN 0.1904762 0.0952381 0.0952381 0.04761905 0.04761905
## QUAI DE LA RAPEE 0.3137255 0.4230769 0.4423077 0.34615385 0.40384615
## CHOISY POINT D'IVRY 0.4583333 0.6250000 0.7916667 0.58333333 0.58333333
## 39 40 41 42 43
## EURYALE DEHAYNIN 0.53571429 0.57142857 0.57142857 0.57142857 0.57142857
## LEMERCIER 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000
## MEZIERES RENNES 0.28260870 0.34782609 0.34782609 0.34782609 0.34782609
## FARMAN 0.04761905 0.04761905 0.04761905 0.04761905 0.04761905
## QUAI DE LA RAPEE 0.35849057 0.43396226 0.39622642 0.32075472 0.32075472
## CHOISY POINT D'IVRY 0.75000000 0.70833333 0.70833333 0.70833333 0.70833333
## 44 45 46 47 48
## EURYALE DEHAYNIN 0.57142857 0.57142857 0.5357143 0.1111111 0.00000000
## LEMERCIER 1.00000000 1.00000000 1.0000000 0.0000000 0.04347826
## MEZIERES RENNES 0.34782609 0.34782609 0.2608696 0.5272727 0.65454545
## FARMAN 0.04761905 0.04761905 0.2857143 1.0000000 1.00000000
## QUAI DE LA RAPEE 0.32075472 0.32075472 0.3392857 0.5797101 0.84057971
## CHOISY POINT D'IVRY 0.75000000 0.66666667 0.5833333 0.3333333 0.12500000
## 49 50 51 52 53
## EURYALE DEHAYNIN 0.0000000 0.03703704 0.11111111 0.11111111 0.03703704
## LEMERCIER 0.0000000 0.00000000 0.08695652 0.00000000 0.04347826
## MEZIERES RENNES 0.7272727 0.87272727 0.81818182 1.00000000 0.92727273
## FARMAN 0.9523810 1.00000000 0.57142857 0.61904762 0.85714286
## QUAI DE LA RAPEE 0.8115942 0.73913043 0.62318841 0.75362319 0.91304348
## CHOISY POINT D'IVRY 0.1250000 0.04166667 0.12500000 0.04166667 0.04166667
## 54 55 56 57 58
## EURYALE DEHAYNIN 0.00000000 0.03703704 0.1851852 0.1481481 0.1481481
## LEMERCIER 0.08695652 0.08695652 0.0000000 0.6521739 1.0000000
## MEZIERES RENNES 0.90909091 0.83636364 0.7272727 0.6545455 0.6545455
## FARMAN 0.76190476 0.76190476 0.1428571 0.0952381 0.0952381
## QUAI DE LA RAPEE 0.92647059 0.94202899 0.8985507 0.7536232 0.7205882
## CHOISY POINT D'IVRY 0.08333333 0.33333333 0.3333333 0.7083333 0.5000000
## 59 60 61 62 63
## EURYALE DEHAYNIN 0.2222222 0.6296296 0.4444444 0.2962963 0.2222222
## LEMERCIER 0.9565217 1.0000000 0.9565217 1.0000000 1.0000000
## MEZIERES RENNES 0.8909091 0.9818182 0.9454545 0.8909091 0.4181818
## FARMAN 0.0952381 0.0952381 0.0952381 0.1428571 0.1428571
## QUAI DE LA RAPEE 0.6521739 0.6086957 0.6231884 0.5942029 0.5072464
## CHOISY POINT D'IVRY 0.7916667 0.6250000 0.5416667 0.5000000 0.4583333
## 64 65 66 67 68
## EURYALE DEHAYNIN 0.4814815 0.5555556 0.5925926 0.5925926 0.5925926
## LEMERCIER 0.8260870 0.8260870 0.8260870 0.8260870 0.8260870
## MEZIERES RENNES 0.4000000 0.4000000 0.4000000 0.2363636 0.2363636
## FARMAN 0.0952381 0.1904762 0.1904762 0.1904762 0.1904762
## QUAI DE LA RAPEE 0.4347826 0.3913043 0.3623188 0.3478261 0.2753623
## CHOISY POINT D'IVRY 0.5416667 0.6666667 0.6666667 0.7083333 0.7083333
## 69 70 71 72 73
## EURYALE DEHAYNIN 0.5555556 0.5185185 0.18518519 0.00000000 0.00000000
## LEMERCIER 0.8260870 0.6956522 0.00000000 0.04347826 0.00000000
## MEZIERES RENNES 0.2181818 0.1090909 0.12727273 0.23636364 0.32727273
## FARMAN 0.1904762 0.4761905 1.00000000 1.00000000 1.00000000
## QUAI DE LA RAPEE 0.2753623 0.2608696 0.54411765 0.79411765 0.82352941
## CHOISY POINT D'IVRY 0.6666667 0.5000000 0.04166667 0.08333333 0.08333333
## 74 75 76 77 78
## EURYALE DEHAYNIN 0.00000000 0.0000000 0.0000000 0.03571429 0.14285714
## LEMERCIER 0.04347826 0.0000000 0.0000000 0.04347826 0.08695652
## MEZIERES RENNES 0.49090909 0.4727273 0.5272727 0.49090909 0.45454545
## FARMAN 0.88888889 0.1111111 0.1666667 0.27777778 0.50000000
## QUAI DE LA RAPEE 0.80597015 0.6764706 0.6470588 0.69117647 0.80597015
## CHOISY POINT D'IVRY 0.00000000 0.1250000 0.1666667 0.25000000 0.33333333
## 79 80 81 82 83
## EURYALE DEHAYNIN 0.00000000 0.10714286 0.5000000 1.0000000 0.9642857
## LEMERCIER 0.08695652 0.21739130 0.6086957 0.8695652 0.7826087
## MEZIERES RENNES 0.45454545 0.47272727 0.3272727 0.3818182 0.4363636
## FARMAN 0.50000000 0.05555556 0.0000000 0.1111111 0.0000000
## QUAI DE LA RAPEE 0.81538462 0.68181818 0.5606061 0.5454545 0.5454545
## CHOISY POINT D'IVRY 0.41666667 0.16666667 0.3750000 0.3750000 0.1666667
## 84 85 86 87 88
## EURYALE DEHAYNIN 0.9642857 0.7777778 0.3333333 0.2857143 0.46428571
## LEMERCIER 0.8695652 0.9565217 1.0000000 0.9130435 0.95652174
## MEZIERES RENNES 0.4363636 0.4000000 0.3818182 0.4181818 0.40000000
## FARMAN 0.0000000 0.0000000 0.0000000 0.0000000 0.00000000
## QUAI DE LA RAPEE 0.4925373 0.3382353 0.2500000 0.1470588 0.05882353
## CHOISY POINT D'IVRY 0.2500000 0.5000000 0.4583333 0.6250000 0.58333333
## 89 90 91 92 93
## EURYALE DEHAYNIN 0.57142857 0.50000000 0.50000000 0.50000000 0.46428571
## LEMERCIER 0.95652174 1.00000000 1.00000000 1.00000000 1.00000000
## MEZIERES RENNES 0.41818182 0.41818182 0.43636364 0.43636364 0.41818182
## FARMAN 0.00000000 0.00000000 0.00000000 0.00000000 0.11111111
## QUAI DE LA RAPEE 0.05882353 0.07352941 0.05882353 0.05882353 0.05882353
## CHOISY POINT D'IVRY 0.58333333 0.62500000 0.62500000 0.62500000 0.50000000
## 94 95 96 97 98
## EURYALE DEHAYNIN 0.5000000 0.03571429 0.07142857 0.07142857 0.07142857
## LEMERCIER 0.7826087 0.00000000 0.00000000 0.00000000 0.04347826
## MEZIERES RENNES 0.3272727 0.34545455 0.45454545 0.45454545 0.40000000
## FARMAN 0.5294118 0.95238095 1.00000000 1.00000000 0.85714286
## QUAI DE LA RAPEE 0.1029412 0.39705882 0.74626866 0.68656716 0.68656716
## CHOISY POINT D'IVRY 0.3333333 0.04166667 0.00000000 0.08333333 0.16666667
## 99 100 101 102 103
## EURYALE DEHAYNIN 0.1071429 0.2142857 0.21428571 0.03571429 0.03571429
## LEMERCIER 0.0000000 0.0000000 0.08695652 0.13043478 0.17391304
## MEZIERES RENNES 0.4181818 0.5090909 0.43636364 0.58181818 0.61818182
## FARMAN 0.5714286 0.6190476 0.76190476 0.71428571 0.52380952
## QUAI DE LA RAPEE 0.6119403 0.7313433 0.73134328 0.71641791 0.70149254
## CHOISY POINT D'IVRY 0.2500000 0.3333333 0.37500000 0.29166667 0.33333333
## 104 105 106 107 108
## EURYALE DEHAYNIN 0.1071429 0.3214286 0.75000000 1.00000000 0.81481481
## LEMERCIER 0.3478261 0.4782609 1.00000000 1.00000000 1.00000000
## MEZIERES RENNES 0.6181818 0.6181818 0.43636364 0.45454545 0.43636364
## FARMAN 0.0952381 0.0000000 0.04761905 0.04761905 0.04761905
## QUAI DE LA RAPEE 0.6865672 0.6865672 0.53030303 0.68181818 0.65671642
## CHOISY POINT D'IVRY 0.1250000 0.3750000 0.20833333 0.37500000 0.29166667
## 109 110 111 112 113
## EURYALE DEHAYNIN 0.70370370 0.44444444 0.5555556 0.59259259 0.51851852
## LEMERCIER 0.86956522 1.00000000 1.0000000 0.82608696 0.82608696
## MEZIERES RENNES 0.52727273 0.45454545 0.4181818 0.40000000 0.41818182
## FARMAN 0.04761905 0.00000000 0.0952381 0.04761905 0.04761905
## QUAI DE LA RAPEE 0.68656716 0.61194030 0.4925373 0.43283582 0.38805970
## CHOISY POINT D'IVRY 0.16666667 0.08695652 0.1666667 0.16666667 0.20833333
## 114 115 116 117 118
## EURYALE DEHAYNIN 0.62962963 0.59259259 0.66666667 0.59259259 0.70370370
## LEMERCIER 0.82608696 0.82608696 0.82608696 0.73913043 0.39130435
## MEZIERES RENNES 0.40000000 0.40000000 0.40000000 0.40000000 0.25454545
## FARMAN 0.04761905 0.04761905 0.04761905 0.09523810 0.38095238
## QUAI DE LA RAPEE 0.26865672 0.28358209 0.25757576 0.28358209 0.22727273
## CHOISY POINT D'IVRY 0.16666667 0.20833333 0.20833333 0.08333333 0.08333333
## 119 120 121 122 123
## EURYALE DEHAYNIN 0.03571429 0.03571429 0.03571429 0.03571429 0.14285714
## LEMERCIER 0.00000000 0.00000000 0.00000000 0.04347826 0.08695652
## MEZIERES RENNES 0.29629630 0.38888889 0.43636364 0.41818182 0.40000000
## FARMAN 1.00000000 0.61904762 0.76190476 0.71428571 0.42857143
## QUAI DE LA RAPEE 0.49253731 0.86363636 0.86363636 0.83333333 0.83076923
## CHOISY POINT D'IVRY 0.00000000 0.04166667 0.08333333 0.04166667 0.00000000
## 124 125 126 127 128
## EURYALE DEHAYNIN 0.17857143 0.07142857 0.0000000 0.03571429 0.10714286
## LEMERCIER 0.08695652 0.00000000 0.1739130 0.13043478 0.34782609
## MEZIERES RENNES 0.61818182 0.63636364 0.8181818 0.92727273 0.96363636
## FARMAN 0.95238095 0.90476190 0.7619048 0.23809524 0.04761905
## QUAI DE LA RAPEE 0.89393939 0.96969697 0.9696970 0.80000000 0.71212121
## CHOISY POINT D'IVRY 0.08333333 0.04166667 0.2916667 0.41666667 0.33333333
## 129 130 131 132 133
## EURYALE DEHAYNIN 0.4285714 0.8928571 0.82142857 0.9285714 1.0000000
## LEMERCIER 0.7826087 0.9565217 1.00000000 0.8695652 0.9565217
## MEZIERES RENNES 0.9818182 0.9636364 0.85454545 0.7272727 0.7454545
## FARMAN 0.0000000 0.0000000 0.04761905 0.0952381 0.0952381
## QUAI DE LA RAPEE 0.6000000 0.3939394 0.50000000 0.6307692 0.7538462
## CHOISY POINT D'IVRY 0.6666667 0.6666667 0.70833333 0.5833333 0.8750000
## 134 135 136 137 138
## EURYALE DEHAYNIN 0.6428571 0.5357143 0.2500000 0.3214286 0.2857143
## LEMERCIER 1.0000000 1.0000000 1.0000000 1.0000000 1.0000000
## MEZIERES RENNES 0.4727273 0.5636364 0.4909091 0.4727273 0.4545455
## FARMAN 0.1428571 0.0952381 0.0952381 0.1428571 0.1428571
## QUAI DE LA RAPEE 0.7692308 0.8461538 0.7384615 0.6562500 0.6153846
## CHOISY POINT D'IVRY 0.8750000 0.9166667 0.8750000 0.8750000 0.9583333
## 139 140 141 142 143
## EURYALE DEHAYNIN 0.3571429 0.3571429 0.3571429 0.3214286 0.3214286
## LEMERCIER 1.0000000 1.0000000 1.0000000 0.9565217 0.8260870
## MEZIERES RENNES 0.4545455 0.4545455 0.4363636 0.4181818 0.4363636
## FARMAN 0.1428571 0.1428571 0.1428571 0.1428571 0.1428571
## QUAI DE LA RAPEE 0.5000000 0.3939394 0.3484848 0.3030303 0.3484848
## CHOISY POINT D'IVRY 0.9583333 0.9166667 0.7916667 0.6666667 0.7083333
## 144 145 146 147 148
## EURYALE DEHAYNIN 0.3571429 0.3214286 0.2142857 0.2500000 0.03571429
## LEMERCIER 0.8260870 0.6521739 0.5652174 0.3043478 0.13043478
## MEZIERES RENNES 0.4363636 0.5272727 0.5818182 0.5636364 0.50909091
## FARMAN 0.1904762 0.3809524 0.5238095 0.4761905 0.42857143
## QUAI DE LA RAPEE 0.3030303 0.3484848 0.3636364 0.2615385 0.21212121
## CHOISY POINT D'IVRY 0.7916667 0.7083333 0.7500000 0.6666667 0.95833333
## 149 150 151 152 153
## EURYALE DEHAYNIN 0.00000000 0.03571429 0.07142857 0.2857143 0.03571429
## LEMERCIER 0.04347826 0.00000000 0.21739130 0.0000000 0.26086957
## MEZIERES RENNES 0.56363636 0.61818182 0.67272727 0.6181818 0.60000000
## FARMAN 0.38095238 0.52380952 0.61904762 0.5238095 0.57142857
## QUAI DE LA RAPEE 0.25757576 0.28787879 0.26562500 0.0937500 0.06250000
## CHOISY POINT D'IVRY 0.87500000 0.41666667 0.21739130 0.1739130 0.43478261
## 154 155 156 157 158
## EURYALE DEHAYNIN 0.3703704 0.00000000 0.03703704 0.11111111 0.07407407
## LEMERCIER 0.2608696 0.34782609 0.52173913 0.60869565 0.39130435
## MEZIERES RENNES 0.5370370 0.62962963 0.66666667 0.59259259 0.62962963
## FARMAN 0.4285714 0.42857143 0.33333333 0.33333333 0.33333333
## QUAI DE LA RAPEE 0.1428571 0.12500000 0.07812500 0.24242424 0.34848485
## CHOISY POINT D'IVRY 0.3043478 0.04347826 0.04347826 0.08695652 0.13043478
## 159 160 161 162 163
## EURYALE DEHAYNIN 0.1481481 0.1111111 0.1111111 0.14814815 0.14814815
## LEMERCIER 0.3913043 0.5652174 0.6956522 0.69565217 0.69565217
## MEZIERES RENNES 0.6481481 0.5740741 0.5555556 0.50000000 0.50000000
## FARMAN 0.3333333 0.3809524 0.3809524 0.38095238 0.38095238
## QUAI DE LA RAPEE 0.3939394 0.3939394 0.3181818 0.27272727 0.19696970
## CHOISY POINT D'IVRY 0.1739130 0.1739130 0.1739130 0.04347826 0.08695652
## 164 165 166 167 168
## EURYALE DEHAYNIN 0.1481481 0.11111111 0.11111111 0.18518519 0.1111111
## LEMERCIER 0.6956522 0.69565217 0.78260870 0.73913043 0.7391304
## MEZIERES RENNES 0.5000000 0.55555556 0.55555556 0.51851852 0.5370370
## FARMAN 0.3809524 0.38095238 0.38095238 0.38095238 0.5238095
## QUAI DE LA RAPEE 0.1666667 0.16666667 0.12121212 0.10606061 0.1363636
## CHOISY POINT D'IVRY 0.1304348 0.04347826 0.04347826 0.04347826 0.1739130
## 169 170 171 172 173
## EURYALE DEHAYNIN 0.1111111 0.07407407 0.07407407 0.29629630 0.11111111
## LEMERCIER 0.5652174 0.26086957 0.17391304 0.04347826 0.00000000
## MEZIERES RENNES 0.4259259 0.40740741 0.33333333 0.25925926 0.25925926
## FARMAN 0.9047619 1.00000000 1.00000000 1.00000000 1.00000000
## QUAI DE LA RAPEE 0.1818182 0.21212121 0.31818182 0.22727273 0.45454545
## CHOISY POINT D'IVRY 0.1739130 0.08695652 0.26086957 0.34782609 0.08695652
## 174 175 176 177 178
## EURYALE DEHAYNIN 0.1111111 0.14814815 0.30769231 0.07692308 0.11538462
## LEMERCIER 0.2173913 0.13043478 0.04545455 0.17391304 0.17391304
## MEZIERES RENNES 0.2037037 0.12962963 0.14814815 0.29629630 0.31481481
## FARMAN 0.9047619 0.85714286 0.85714286 0.85714286 0.76190476
## QUAI DE LA RAPEE 0.5909091 0.83333333 1.00000000 0.81818182 0.63636364
## CHOISY POINT D'IVRY 0.1153846 0.08695652 0.13043478 0.08695652 0.08695652
## 179 180 181
## EURYALE DEHAYNIN 0.07692308 0.1538462 0.1538462
## LEMERCIER 0.17391304 0.2608696 0.3913043
## MEZIERES RENNES 0.37037037 0.3703704 0.4074074
## FARMAN 0.76190476 0.7619048 0.7619048
## QUAI DE LA RAPEE 0.71212121 0.6212121 0.5757576
## CHOISY POINT D'IVRY 0.43478261 0.3913043 0.5217391
head(coord)
## longitude latitude bonus
## 19117 2.377389 48.88630 0
## 17111 2.317591 48.89002 0
## 6103 2.330447 48.85030 0
## 15042 2.271396 48.83373 0
## 12003 2.366897 48.84589 0
## 13038 2.363335 48.82191 0
intervals = unname(c(summary(rowMeans(loading))[2:5],0.7,1.1))
intervals
## [1] 0.2045739 0.3533516 0.3816218 0.5324596 0.7000000 1.1000000
labels_cat = c("très peu chargé","peu chargé","moyen", "chargé", "très chargé")
# Créer un nouveau DataFrame pour les données catégoriques
categorical_data <- data.frame(matrix(ncol = ncol(loading), nrow = nrow(loading)))
colnames(categorical_data) <- colnames(loading)
# Appliquer la transformation
for (column in colnames(loading)) {
categorical_data[,column] <- cut(loading[,column], breaks = intervals, labels = labels_cat, right = FALSE)
}
categorical_data = replace(categorical_data, is.na(categorical_data), "très peu chargé")
# Afficher les premières lignes du nouveau DataFrame
head(categorical_data)
## 14 15 16 17
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 moyen moyen moyen moyen
## 3 très peu chargé très peu chargé très peu chargé très peu chargé
## 4 très chargé très chargé très chargé très chargé
## 5 très chargé très chargé très chargé très chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 18 19 20 21
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 moyen moyen moyen moyen
## 3 très peu chargé très peu chargé très peu chargé très peu chargé
## 4 très chargé très chargé très chargé très chargé
## 5 très chargé très chargé très chargé très chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 22 23 24 25
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé très peu chargé
## 3 très peu chargé très peu chargé très peu chargé peu chargé
## 4 très chargé très chargé très chargé très chargé
## 5 très chargé très chargé très chargé très chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 26 27 28 29
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé très peu chargé
## 3 moyen très peu chargé peu chargé moyen
## 4 très chargé très chargé très chargé très chargé
## 5 très chargé très chargé très chargé très chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 30 31 32 33
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé très peu chargé
## 3 moyen moyen moyen moyen
## 4 très chargé très chargé très peu chargé très peu chargé
## 5 très chargé très chargé chargé moyen
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 34 35 36 37
## 1 moyen moyen moyen moyen
## 2 très chargé très chargé très chargé très chargé
## 3 moyen très peu chargé moyen très peu chargé
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 très peu chargé moyen moyen très peu chargé
## 6 moyen chargé très chargé chargé
## 38 39 40 41
## 1 moyen chargé chargé chargé
## 2 très chargé très chargé très chargé très chargé
## 3 très peu chargé très peu chargé très peu chargé très peu chargé
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 moyen peu chargé moyen moyen
## 6 chargé très chargé très chargé très chargé
## 42 43 44 45
## 1 chargé chargé chargé chargé
## 2 très chargé très chargé très chargé très chargé
## 3 très peu chargé très peu chargé très peu chargé très peu chargé
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 très peu chargé très peu chargé très peu chargé très peu chargé
## 6 très chargé très chargé très chargé chargé
## 46 47 48 49
## 1 chargé très peu chargé très peu chargé très peu chargé
## 2 très chargé très peu chargé très peu chargé très peu chargé
## 3 très peu chargé moyen chargé très chargé
## 4 très peu chargé très chargé très chargé très chargé
## 5 très peu chargé chargé très chargé très chargé
## 6 chargé très peu chargé très peu chargé très peu chargé
## 50 51 52 53
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé très peu chargé
## 3 très chargé très chargé très chargé très chargé
## 4 très chargé chargé chargé très chargé
## 5 très chargé chargé très chargé très chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 54 55 56 57
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé chargé
## 3 très chargé très chargé très chargé chargé
## 4 très chargé très chargé très peu chargé très peu chargé
## 5 très chargé très chargé très chargé très chargé
## 6 très peu chargé très peu chargé très peu chargé très chargé
## 58 59 60 61
## 1 très peu chargé très peu chargé chargé moyen
## 2 très chargé très chargé très chargé très chargé
## 3 chargé très chargé très chargé très chargé
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 très chargé chargé chargé chargé
## 6 moyen très chargé chargé chargé
## 62 63 64 65
## 1 très peu chargé très peu chargé moyen chargé
## 2 très chargé très chargé très chargé très chargé
## 3 très chargé moyen moyen moyen
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 chargé moyen moyen moyen
## 6 moyen moyen chargé chargé
## 66 67 68 69
## 1 chargé chargé chargé chargé
## 2 très chargé très chargé très chargé très chargé
## 3 moyen très peu chargé très peu chargé très peu chargé
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 peu chargé très peu chargé très peu chargé très peu chargé
## 6 chargé très chargé très chargé chargé
## 70 71 72 73
## 1 moyen très peu chargé très peu chargé très peu chargé
## 2 chargé très peu chargé très peu chargé très peu chargé
## 3 très peu chargé très peu chargé très peu chargé très peu chargé
## 4 moyen très chargé très chargé très chargé
## 5 très peu chargé chargé très chargé très chargé
## 6 moyen très peu chargé très peu chargé très peu chargé
## 74 75 76 77
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé très peu chargé
## 3 moyen moyen moyen moyen
## 4 très chargé très peu chargé très peu chargé très peu chargé
## 5 très chargé chargé chargé chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 78 79 80 81
## 1 très peu chargé très peu chargé très peu chargé moyen
## 2 très peu chargé très peu chargé très peu chargé chargé
## 3 moyen moyen moyen très peu chargé
## 4 moyen moyen très peu chargé très peu chargé
## 5 très chargé très chargé chargé chargé
## 6 très peu chargé moyen très peu chargé peu chargé
## 82 83 84 85
## 1 très chargé très chargé très chargé très chargé
## 2 très chargé très chargé très chargé très chargé
## 3 moyen moyen moyen moyen
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 chargé chargé moyen très peu chargé
## 6 peu chargé très peu chargé très peu chargé moyen
## 86 87 88 89
## 1 très peu chargé très peu chargé moyen chargé
## 2 très chargé très chargé très chargé très chargé
## 3 moyen moyen moyen moyen
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 très peu chargé très peu chargé très peu chargé très peu chargé
## 6 moyen chargé chargé chargé
## 90 91 92 93
## 1 moyen moyen moyen moyen
## 2 très chargé très chargé très chargé très chargé
## 3 moyen moyen moyen moyen
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 très peu chargé très peu chargé très peu chargé très peu chargé
## 6 chargé chargé chargé moyen
## 94 95 96 97
## 1 moyen très peu chargé très peu chargé très peu chargé
## 2 très chargé très peu chargé très peu chargé très peu chargé
## 3 très peu chargé très peu chargé moyen moyen
## 4 moyen très chargé très chargé très chargé
## 5 très peu chargé moyen très chargé chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 98 99 100 101
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé très peu chargé
## 3 moyen moyen moyen moyen
## 4 très chargé chargé chargé très chargé
## 5 chargé chargé très chargé très chargé
## 6 très peu chargé très peu chargé très peu chargé peu chargé
## 102 103 104 105
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé moyen
## 3 chargé chargé chargé chargé
## 4 très chargé moyen très peu chargé très peu chargé
## 5 très chargé très chargé chargé chargé
## 6 très peu chargé très peu chargé très peu chargé peu chargé
## 106 107 108 109
## 1 très chargé très chargé très chargé très chargé
## 2 très chargé très chargé très chargé très chargé
## 3 moyen moyen moyen moyen
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 moyen chargé chargé chargé
## 6 très peu chargé peu chargé très peu chargé très peu chargé
## 110 111 112 113
## 1 moyen chargé chargé moyen
## 2 très chargé très chargé très chargé très chargé
## 3 moyen moyen moyen moyen
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 chargé moyen moyen moyen
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 114 115 116 117
## 1 chargé chargé chargé chargé
## 2 très chargé très chargé très chargé très chargé
## 3 moyen moyen moyen moyen
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 très peu chargé très peu chargé très peu chargé très peu chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 118 119 120 121
## 1 très chargé très peu chargé très peu chargé très peu chargé
## 2 moyen très peu chargé très peu chargé très peu chargé
## 3 très peu chargé très peu chargé moyen moyen
## 4 peu chargé très chargé chargé très chargé
## 5 très peu chargé moyen très chargé très chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 122 123 124 125
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé très peu chargé
## 3 moyen moyen chargé chargé
## 4 très chargé moyen très chargé très chargé
## 5 très chargé très chargé très chargé très chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 126 127 128 129
## 1 très peu chargé très peu chargé très peu chargé moyen
## 2 très peu chargé très peu chargé très peu chargé très chargé
## 3 très chargé très chargé très chargé très chargé
## 4 très chargé très peu chargé très peu chargé très peu chargé
## 5 très chargé très chargé très chargé chargé
## 6 très peu chargé moyen très peu chargé chargé
## 130 131 132 133
## 1 très chargé très chargé très chargé très chargé
## 2 très chargé très chargé très chargé très chargé
## 3 très chargé très chargé très chargé très chargé
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 moyen moyen chargé très chargé
## 6 chargé très chargé chargé très chargé
## 134 135 136 137
## 1 chargé chargé très peu chargé très peu chargé
## 2 très chargé très chargé très chargé très chargé
## 3 moyen chargé moyen moyen
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 très chargé très chargé très chargé chargé
## 6 très chargé très chargé très chargé très chargé
## 138 139 140 141
## 1 très peu chargé peu chargé peu chargé peu chargé
## 2 très chargé très chargé très chargé très chargé
## 3 moyen moyen moyen moyen
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 chargé moyen moyen très peu chargé
## 6 très chargé très chargé très chargé très chargé
## 142 143 144 145
## 1 très peu chargé très peu chargé peu chargé très peu chargé
## 2 très chargé très chargé très chargé chargé
## 3 moyen moyen moyen moyen
## 4 très peu chargé très peu chargé très peu chargé peu chargé
## 5 très peu chargé très peu chargé très peu chargé très peu chargé
## 6 chargé très chargé très chargé très chargé
## 146 147 148 149
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 chargé très peu chargé très peu chargé très peu chargé
## 3 chargé chargé moyen chargé
## 4 moyen moyen moyen peu chargé
## 5 peu chargé très peu chargé très peu chargé très peu chargé
## 6 très chargé chargé très chargé très chargé
## 150 151 152 153
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé très peu chargé
## 3 chargé chargé chargé chargé
## 4 moyen chargé moyen chargé
## 5 très peu chargé très peu chargé très peu chargé très peu chargé
## 6 moyen très peu chargé très peu chargé moyen
## 154 155 156 157
## 1 peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé moyen chargé
## 3 chargé chargé chargé chargé
## 4 moyen moyen très peu chargé très peu chargé
## 5 très peu chargé très peu chargé très peu chargé très peu chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 158 159 160 161
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 moyen moyen chargé chargé
## 3 chargé chargé chargé chargé
## 4 très peu chargé très peu chargé peu chargé peu chargé
## 5 très peu chargé moyen moyen très peu chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 162 163 164 165
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 chargé chargé chargé chargé
## 3 moyen moyen moyen chargé
## 4 peu chargé peu chargé peu chargé peu chargé
## 5 très peu chargé très peu chargé très peu chargé très peu chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 166 167 168 169
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très chargé très chargé très chargé chargé
## 3 chargé moyen chargé moyen
## 4 peu chargé peu chargé moyen très chargé
## 5 très peu chargé très peu chargé très peu chargé très peu chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 170 171 172 173
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé très peu chargé
## 3 moyen très peu chargé très peu chargé très peu chargé
## 4 très chargé très chargé très chargé très chargé
## 5 très peu chargé très peu chargé très peu chargé moyen
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 174 175 176 177
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé très peu chargé
## 3 très peu chargé très peu chargé très peu chargé très peu chargé
## 4 très chargé très chargé très chargé très chargé
## 5 chargé très chargé très chargé très chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## 178 179 180 181
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé moyen
## 3 très peu chargé peu chargé peu chargé moyen
## 4 très chargé très chargé très chargé très chargé
## 5 chargé très chargé chargé chargé
## 6 très peu chargé moyen moyen moyen
loading =as.data.frame(loading)
RemplissageMoyenStation = rowMeans(loading)
#RemplissageMoyenStationSort = sort(RemplissageMoyenStation, decreasing = TRUE)
#plot(RemplissageMoyenStationSort)
RemplissageMoyenHeure = colMeans(loading)
lundi = loading[,c(0:24)]
mardi = loading[,c(25:48)]
mercredi = loading[,c(49:72)]
jeudi = loading[,c(73:96)]
vendredi = loading[,c(97:120)]
samedi = loading[,c(121:144)]
dimanche = loading[,c(145:168)]
lundiMoyHeure = RemplissageMoyenHeure[c(0:24)]
mardiMoyHeure = RemplissageMoyenHeure[c(25:48)]
mercrediMoyHeure = RemplissageMoyenHeure[c(49:72)]
jeudiMoyHeure = RemplissageMoyenHeure[c(73:96)]
vendrediMoyHeure = RemplissageMoyenHeure[c(97:120)]
samediMoyHeure = RemplissageMoyenHeure[c(121:144)]
dimancheMoyHeure = RemplissageMoyenHeure[c(145:168)]
lundiMoy = rowMeans(loading[, c(1:24)])
mardiMoy = rowMeans(loading[, c(25:48)])
mercrediMoy = rowMeans(loading[, c(49:72)])
jeudiMoy = rowMeans(loading[, c(73:96)])
vendrediMoy = rowMeans(loading[, c(97:120)])
samediMoy = rowMeans(loading[, c(121:144)])
dimancheMoy = rowMeans(loading[, c(145:168)])
lundiRepos = as.data.frame(c(lundi[0:7],lundi[20:24]))
lundiTravail = as.data.frame(c(lundi[8:19]))
mardiRepos = as.data.frame(c(mardi[0:7],mardi[20:24]))
mardiTravail = as.data.frame(c(mardi[8:19]))
mercrediRepos = as.data.frame(c(mercredi[0:7],mercredi[20:24]))
mercrediTravail = as.data.frame(c(mercredi[8:19]))
jeudiRepos = as.data.frame(c(jeudi[0:7],jeudi[20:24]))
jeudiTravail = as.data.frame(c(jeudi[8:19]))
vendrediRepos = as.data.frame(c(vendredi[0:7],vendredi[20:24]))
vendrediTravail = as.data.frame(c(vendredi[8:19]))
samediRepos = as.data.frame(c(samedi[0:7],samedi[20:24]))
samediTravail = as.data.frame(c(samedi[8:19]))
dimancheRepos = as.data.frame(c(dimanche[0:7],dimanche[20:24]))
dimancheTravail = as.data.frame(c(dimanche[8:19]))
jours = cbind(lundi,mardi,mercredi,jeudi,vendredi,samedi,dimanche)
joursMoy = cbind(lundiMoy,mardiMoy,mercrediMoy,jeudiMoy,vendrediMoy,samediMoy,dimancheMoy)
joursTravail = cbind(lundiTravail,mardiTravail,mercrediTravail,jeudiTravail,vendrediTravail,samediTravail,dimancheTravail)
joursRepos = cbind(lundiRepos,mardiRepos,mercrediRepos,jeudiRepos,vendrediRepos,samediRepos,dimancheRepos)
joursTravailMoy = cbind(rowMeans(lundiTravail),rowMeans(mardiTravail),rowMeans(mercrediTravail),rowMeans(jeudiTravail),rowMeans(vendrediTravail),rowMeans(samediTravail),rowMeans(dimancheTravail))
joursReposMoy = cbind(rowMeans(lundiRepos),rowMeans(mardiRepos),rowMeans(mercrediRepos),rowMeans(jeudiRepos),rowMeans(vendrediRepos),rowMeans(samediRepos),rowMeans(dimancheRepos))
colnames(joursReposMoy) = c("LundiRepos","MardiRepos", "MercrediRepos","JeudiRepos","VendrediRepos","SamediRepos","DimancheRepos")
colnames(joursTravailMoy) = c("LundiTravail","MardiTravail", "MercrediTravail","JeudiTravail","VendrediTravail","SamediTravail","DimancheTravail")
#corrplot(cor(jours),method="ellipse")
# Créer un nouveau DataFrame pour les données catégoriques
load_quali = data.frame(matrix(ncol = ncol(joursTravailMoy)*2, nrow = nrow(joursTravailMoy)))
#load_quali = rbind(joursTravailMoy,joursReposMoy)
colnames(load_quali) <- c(colnames(joursTravailMoy),colnames(joursReposMoy))
# Appliquer la transformation
for (column in colnames(joursTravailMoy)) {
load_quali[,column] <- cut(joursTravailMoy[,column], breaks = intervals, labels = labels_cat, right = FALSE)
}
for (column in colnames(joursReposMoy)) {
load_quali[,column] <- cut(joursReposMoy[,column], breaks = intervals, labels = labels_cat, right = FALSE)
}
load_quali = replace(load_quali, is.na(load_quali), "très peu chargé")
load_quali = cbind(load_quali, coord$bonus)
names(load_quali)[names(load_quali) == "coord$bonus"] <- "bonus"
load_quali$bonus[load_quali$bonus == 1] <- "colline"
load_quali$bonus[load_quali$bonus == 0] <- "plaine"
# Afficher les premières lignes du nouveau DataFrame
head(load_quali)
## LundiTravail MardiTravail MercrediTravail JeudiTravail
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé très peu chargé très peu chargé très peu chargé
## 3 très peu chargé très chargé peu chargé moyen
## 4 très chargé chargé moyen chargé
## 5 très chargé très chargé chargé chargé
## 6 très peu chargé très peu chargé très peu chargé très peu chargé
## VendrediTravail SamediTravail DimancheTravail LundiRepos
## 1 très peu chargé très peu chargé très peu chargé très peu chargé
## 2 très peu chargé moyen peu chargé chargé
## 3 chargé moyen peu chargé très peu chargé
## 4 chargé peu chargé très chargé chargé
## 5 très chargé très peu chargé peu chargé chargé
## 6 très peu chargé chargé très peu chargé très peu chargé
## MardiRepos MercrediRepos JeudiRepos VendrediRepos
## 1 moyen chargé chargé chargé
## 2 très chargé très chargé très chargé très chargé
## 3 chargé moyen moyen chargé
## 4 très peu chargé très peu chargé très peu chargé très peu chargé
## 5 moyen moyen très peu chargé moyen
## 6 chargé moyen moyen moyen
## SamediRepos DimancheRepos bonus
## 1 très peu chargé très peu chargé plaine
## 2 très chargé moyen plaine
## 3 chargé moyen plaine
## 4 très peu chargé chargé plaine
## 5 moyen moyen plaine
## 6 chargé très peu chargé plaine
head(joursTravailMoy)
## LundiTravail MardiTravail MercrediTravail JeudiTravail VendrediTravail
## [1,] 0.03296703 0.1447310 0.1287478 0.1607143 0.1645723
## [2,] 0.10869565 0.1956522 0.1702899 0.2137681 0.1666667
## [3,] 0.31257043 0.7173913 0.3651515 0.4651515 0.5464927
## [4,] 0.92063492 0.6666667 0.5138889 0.6446467 0.5753968
## [5,] 0.86278902 0.7239967 0.6518205 0.5714442 0.7283518
## [6,] 0.08333333 0.2361111 0.2361111 0.2361111 0.1250000
## SamediTravail DimancheTravail
## [1,] 0.2142857 0.1460114
## [2,] 0.4601449 0.3661067
## [3,] 0.5318182 0.3611111
## [4,] 0.3730159 0.7658730
## [5,] 0.2828034 0.3623737
## [6,] 0.6437198 0.1328038
head(joursReposMoy)
## LundiRepos MardiRepos MercrediRepos JeudiRepos VendrediRepos SamediRepos
## [1,] 0.1893315 0.44819224 0.6283069 0.56205908 0.67261905 0.2753527
## [2,] 0.5760870 0.96376812 0.8514493 0.93115942 0.89130435 0.7500000
## [3,] 0.2351779 0.53596838 0.4136364 0.44848485 0.59696970 0.5324635
## [4,] 0.5992063 0.06746032 0.1044974 0.01587302 0.04761905 0.2500000
## [5,] 0.6104294 0.49275491 0.4496109 0.32898786 0.46781187 0.4308605
## [6,] 0.3229167 0.67361111 0.4930556 0.46180556 0.39266304 0.6073370
## DimancheRepos
## [1,] 0.1221510
## [2,] 0.4420290
## [3,] 0.4722222
## [4,] 0.5396825
## [5,] 0.4545455
## [6,] 0.2028986
sum(is.na(loading))
## [1] 0
sum(is.na(coord))
## [1] 0
sum(duplicated(loading))
## [1] 0
days = c(0,24,48,72,96,120,144,168)
i = 5
plot(c(1:168),loading[i,],type="l",main = paste("Evolution de la disponibilité à la station",rownames(loading)[i]),cex=0.1)
abline(v = days, col="red")
abline(v = days+12, col="darkgreen",lty=2)
i_array = sample(1:1000,9)
par(mfrow=c(3,3))
for (i in 1:9) {
plot(c(1:168),loading[i_array[i],],type="l" ,xlab = row.names(loading[i,]))
abline(v = days, col="red")
}
plot(RemplissageMoyenHeure,type='l', main = "Remplissage moyen par heure")
abline(v = days, col="red")
abline(v = days+12, col="darkgreen",lty=2)
abline(h = mean(RemplissageMoyenHeure), col = 'blue')
plot(rowMeans(loading), type='l', main = "Remplissage moyen par station")
abline(h = mean(RemplissageMoyenHeure), col = 'blue')
listPlot = list()
h = 18
hours = 24*c(0:6) + h
nomJours = c("Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche")
dfi = coord
for (i in 1:7){
dfi$loading = loading[,hours[i]]
listPlot[[i]] = ggplot(dfi, aes(x = longitude, y = latitude, color = loading)) + geom_point() + ggtitle(paste("Chargement des stations ",nomJours[i], "Ã ",h,"heures."))
}
do.call(grid.arrange,c(listPlot,ncol=2))
# Le lundi, à différentes heures
hours = c(1, 6, 12, 18, 22)
listPlot = list()
dfi = coord
for (i in 1:5){
dfi$loading = loading[,hours[i]]
listPlot[[i]] = ggplot(dfi, aes(x = longitude, y = latitude, color = loading)) + geom_point() + ggtitle(paste("Chargement des stations lundi à ",hours[i],"heures."))
}
do.call(grid.arrange,c(listPlot,ncol=2))
#Chargement moyen à 18h
h = 18
hours = 24*c(0:6) + h
loading18h = loading[hours]
head(loading18h)
## 31 55 79 103 127
## X.EURYALE.DEHAYNIN 0.10714286 0.03703704 0.00000000 0.03571429 0.03571429
## X.LEMERCIER 0.04347826 0.08695652 0.08695652 0.17391304 0.13043478
## X.MEZIERES.RENNES 0.50000000 0.83636364 0.45454545 0.61818182 0.92727273
## X.FARMAN 0.95238095 0.76190476 0.50000000 0.52380952 0.23809524
## X.QUAI.DE.LA.RAPEE 0.79245283 0.94202899 0.81538462 0.70149254 0.80000000
## X.CHOISY.POINT.D.IVRY 0.04166667 0.33333333 0.41666667 0.33333333 0.41666667
## 151 175
## X.EURYALE.DEHAYNIN 0.07142857 0.14814815
## X.LEMERCIER 0.21739130 0.13043478
## X.MEZIERES.RENNES 0.67272727 0.12962963
## X.FARMAN 0.61904762 0.85714286
## X.QUAI.DE.LA.RAPEE 0.26562500 0.83333333
## X.CHOISY.POINT.D.IVRY 0.21739130 0.08695652
dfi = coord
dfi$loading = rowMeans(loading18h)
ggplot(dfi, aes(x = longitude, y = latitude, color = loading)) + geom_point() + ggtitle(paste("Chargement Moyen à ",h,"heures"))
pie(c(sum(coord$bonus == 1), sum(coord$bonus == 0)), label = c("Stations en altitude","Stations en plaine"))
dfi = coord
ggplot(dfi, aes(x = longitude, y = latitude, color = bonus)) + geom_point() + ggtitle("Stations en altitude")
data_scale = scale(loading)
pca = PCA(data_scale,ncp = 5,graph=FALSE)
data_pca = pca$ind$coord
grid.arrange(
fviz_eig(pca),
fviz_pca_var(pca,axes=c(1,2),label=""),
fviz_pca_var(pca,axes=c(2,3),label=""),
ncol=3
)
print(pca$eig[1:10,])
## eigenvalue percentage of variance cumulative percentage of variance
## comp 1 66.888963 39.814859 39.81486
## comp 2 39.486446 23.503837 63.31870
## comp 3 8.867649 5.278363 68.59706
## comp 4 7.305326 4.348408 72.94547
## comp 5 5.503113 3.275662 76.22113
## comp 6 3.245742 1.931989 78.15312
## comp 7 2.829095 1.683985 79.83710
## comp 8 2.684309 1.597803 81.43491
## comp 9 2.157416 1.284176 82.71908
## comp 10 2.057260 1.224560 83.94364
plot(pca$eig[,2], type = 'l', main = "Variance expliquée par composantes")
plot(pca$eig[1:10,2], type = 'l', main = "Variance expliquée par les 10 premières composantes")
plot(pca$var$coord[,2],type='l',col='blue', main = "Première et deuxième composante principale")
lines(pca$var$coord[,1],type='l',col='red')
fviz_pca_ind(pca, label ="" , title= "Graphe des individus suivant les composantes 1 & 2")
fviz_pca_ind(pca, axes = c(1,3), label ="" , title= "Graphe des individus suivant les composantes 1 & 3")
hab <- ifelse(RemplissageMoyenStation <= 0.4, 'faible',
ifelse(RemplissageMoyenStation <= 0.6, 'moyen', 'élevé'))
fviz_pca_ind(pca,label="",habillage = as.factor(hab), title = "Graphes des individus colorés suivant le remplissage moyen")
corrplot(cor(joursMoy), method="ellipse")
joursScale = scale(joursMoy)
pcaJours = PCA(joursScale,ncp = 5,graph=FALSE)
summary(pcaJours)
##
## Call:
## PCA(X = joursScale, ncp = 5, graph = FALSE)
##
##
## Eigenvalues
## Dim.1 Dim.2 Dim.3 Dim.4 Dim.5 Dim.6 Dim.7
## Variance 5.329 0.571 0.439 0.243 0.177 0.124 0.117
## % of var. 76.128 8.152 6.275 3.478 2.530 1.770 1.667
## Cumulative % of var. 76.128 84.280 90.555 94.033 96.563 98.333 100.000
##
## Individuals (the 10 first)
## Dist Dim.1 ctr cos2 Dim.2
## X.EURYALE.DEHAYNIN | 1.491 | -1.013 0.016 0.462 | -0.397
## X.LEMERCIER | 1.713 | 1.428 0.032 0.695 | -0.219
## X.MEZIERES.RENNES | 1.584 | 0.993 0.016 0.393 | 0.034
## X.FARMAN | 1.888 | 0.417 0.003 0.049 | 0.438
## X.QUAI.DE.LA.RAPEE | 2.149 | 1.689 0.045 0.618 | -0.830
## X.CHOISY.POINT.D.IVRY | 1.501 | -0.377 0.002 0.063 | 0.084
## X.PORTE.DE.VILLIERS | 1.147 | 0.230 0.001 0.040 | 0.573
## X.STALINGRAD..FONTENAY.SOUS.BOIS. | 0.998 | 0.076 0.000 0.006 | 0.485
## X.GARE.RER..JOINVILLE. | 2.935 | 2.450 0.095 0.697 | 0.352
## X.MOUFFETARD.EPEE.DE.BOIS | 3.481 | 0.697 0.008 0.040 | -1.637
## ctr cos2 Dim.3 ctr cos2
## X.EURYALE.DEHAYNIN 0.023 0.071 | -0.970 0.180 0.424 |
## X.LEMERCIER 0.007 0.016 | -0.691 0.091 0.163 |
## X.MEZIERES.RENNES 0.000 0.000 | -0.574 0.063 0.131 |
## X.FARMAN 0.028 0.054 | 1.641 0.515 0.755 |
## X.QUAI.DE.LA.RAPEE 0.102 0.149 | 0.741 0.105 0.119 |
## X.CHOISY.POINT.D.IVRY 0.001 0.003 | -0.445 0.038 0.088 |
## X.PORTE.DE.VILLIERS 0.048 0.249 | -0.259 0.013 0.051 |
## X.STALINGRAD..FONTENAY.SOUS.BOIS. 0.035 0.236 | -0.375 0.027 0.141 |
## X.GARE.RER..JOINVILLE. 0.018 0.014 | 1.468 0.412 0.250 |
## X.MOUFFETARD.EPEE.DE.BOIS 0.395 0.221 | 2.801 1.502 0.647 |
##
## Variables
## Dim.1 ctr cos2 Dim.2 ctr cos2
## lundiMoy | 0.824 12.754 0.680 | -0.114 2.268 0.013
## mardiMoy | 0.896 15.074 0.803 | -0.238 9.897 0.056
## mercrediMoy | 0.883 14.642 0.780 | -0.300 15.760 0.090
## jeudiMoy | 0.888 14.812 0.789 | -0.222 8.657 0.049
## vendrediMoy | 0.898 15.116 0.806 | 0.049 0.424 0.002
## samediMoy | 0.871 14.251 0.759 | 0.398 27.705 0.158
## dimancheMoy | 0.843 13.351 0.711 | 0.449 35.288 0.201
## Dim.3 ctr cos2
## lundiMoy | 0.501 57.213 0.251 |
## mardiMoy | 0.140 4.480 0.020 |
## mercrediMoy | -0.113 2.883 0.013 |
## jeudiMoy | -0.254 14.641 0.064 |
## vendrediMoy | -0.249 14.166 0.062 |
## samediMoy | -0.113 2.896 0.013 |
## dimancheMoy | 0.128 3.722 0.016 |
plot(pcaJours$eig[1:5,2], type='l')
fviz_pca_ind(pcaJours, label ="" , title= "Graphe des individus suivant les composantes 1 & 2")
fviz_pca_ind(pcaJours, axes = c(1,3), label ="" , title= "Graphe des individus suivant les composantes 1 & 3")
grid.arrange(
fviz_eig(pcaJours),
fviz_pca_var(pcaJours,axes=c(1,2)),
fviz_pca_var(pcaJours,axes=c(2,3)),
ncol=3
)
corrplot(cor(joursTravailMoy),method="ellipse")
corrplot(cor(joursReposMoy),method="ellipse")
corrplot(cor(cbind(joursTravailMoy,joursReposMoy)),method="ellipse")
library(leaflet)
library(dplyr)
# Set your Stadia Maps API key
apikey <- "bdfc537c-e86b-4abb-8c63-4cedfa75cadd"
j <- 0
h <- 6
jours_data <- loading[, j*24 + h]
pal <- colorNumeric(palette = "inferno", domain = jours_data)
# Create a leaflet map
map <- leaflet(data = coord) %>%
addProviderTiles(provider = leaflet::providers$Stadia.AlidadeSmooth,
options = providerTileOptions(apikey = apikey)) %>%
addCircles(lng = ~longitude, lat = ~latitude, color = ~pal(jours_data),
fillOpacity = 0.8, radius = 40) %>%
addLegend( pal = pal, values = jours_data,
title = paste("Remplissage jour", j, "Ã ", h, "h"),
opacity = 1)
map
joursTR_Moy = cbind(joursTravailMoy,joursReposMoy)
joursTR_scale = scale(joursTR_Moy)
pcaJoursTR = PCA(joursTR_scale,ncp = 5,graph=FALSE)
grid.arrange(
fviz_eig(pcaJoursTR),
fviz_pca_var(pcaJoursTR,axes=c(1,2)),
ncol=2
)
fviz_pca_var(pcaJoursTR,axes=c(1,3))
print(pcaJoursTR$eig)
## eigenvalue percentage of variance cumulative percentage of variance
## comp 1 7.83428380 55.9591700 55.95917
## comp 2 3.27060410 23.3614579 79.32063
## comp 3 0.88568181 6.3262986 85.64693
## comp 4 0.58678235 4.1913025 89.83823
## comp 5 0.31731367 2.2665262 92.10476
## comp 6 0.26200210 1.8714436 93.97620
## comp 7 0.20929795 1.4949854 95.47118
## comp 8 0.17693185 1.2637989 96.73498
## comp 9 0.13314310 0.9510221 97.68601
## comp 10 0.09609753 0.6864109 98.37242
## comp 11 0.07481943 0.5344245 98.90684
## comp 12 0.05902362 0.4215973 99.32844
## comp 13 0.05061334 0.3615239 99.68996
## comp 14 0.04340534 0.3100382 100.00000
plot(pcaJoursTR$eig[1:5,2], type='l')
fviz_pca_ind(pcaJoursTR ,label = "", title= "Graphe des individus suivant les composantes 1 & 2")
fviz_pca_ind(pcaJoursTR, axes = c(1,3) ,label = "", title= "Graphe des individus suivant les composantes 1 & 3")
plot(pcaJoursTR$var$coord[,1],type='l',col='blue', main = "Première composante principale")
plot(pcaJoursTR$var$coord[,2],type='l',col='red', main = "Deuxième composante principale")
res.mca = MCA(load_quali, graph = FALSE)
summary(res.mca)
##
## Call:
## MCA(X = load_quali, graph = FALSE)
##
##
## Eigenvalues
## Dim.1 Dim.2 Dim.3 Dim.4 Dim.5 Dim.6 Dim.7
## Variance 0.487 0.236 0.192 0.128 0.113 0.101 0.091
## % of var. 12.805 6.212 5.044 3.366 2.970 2.652 2.382
## Cumulative % of var. 12.805 19.017 24.061 27.427 30.396 33.048 35.431
## Dim.8 Dim.9 Dim.10 Dim.11 Dim.12 Dim.13 Dim.14
## Variance 0.087 0.086 0.084 0.081 0.079 0.078 0.077
## % of var. 2.282 2.261 2.199 2.130 2.089 2.045 2.014
## Cumulative % of var. 37.712 39.973 42.172 44.302 46.391 48.436 50.450
## Dim.15 Dim.16 Dim.17 Dim.18 Dim.19 Dim.20 Dim.21
## Variance 0.075 0.073 0.070 0.070 0.067 0.066 0.065
## % of var. 1.981 1.929 1.843 1.836 1.764 1.729 1.709
## Cumulative % of var. 52.430 54.359 56.202 58.038 59.802 61.532 63.241
## Dim.22 Dim.23 Dim.24 Dim.25 Dim.26 Dim.27 Dim.28
## Variance 0.065 0.063 0.063 0.062 0.060 0.058 0.058
## % of var. 1.706 1.669 1.652 1.626 1.572 1.527 1.521
## Cumulative % of var. 64.947 66.616 68.268 69.894 71.466 72.993 74.514
## Dim.29 Dim.30 Dim.31 Dim.32 Dim.33 Dim.34 Dim.35
## Variance 0.056 0.056 0.054 0.053 0.052 0.051 0.049
## % of var. 1.485 1.473 1.424 1.397 1.375 1.347 1.297
## Cumulative % of var. 75.999 77.472 78.896 80.293 81.668 83.014 84.312
## Dim.36 Dim.37 Dim.38 Dim.39 Dim.40 Dim.41 Dim.42
## Variance 0.049 0.047 0.046 0.044 0.043 0.043 0.040
## % of var. 1.287 1.226 1.199 1.168 1.140 1.136 1.048
## Cumulative % of var. 85.599 86.825 88.023 89.191 90.332 91.468 92.516
## Dim.43 Dim.44 Dim.45 Dim.46 Dim.47 Dim.48 Dim.49
## Variance 0.037 0.036 0.035 0.030 0.028 0.021 0.020
## % of var. 0.974 0.959 0.914 0.784 0.740 0.549 0.529
## Cumulative % of var. 93.489 94.448 95.363 96.147 96.887 97.435 97.964
## Dim.50 Dim.51 Dim.52 Dim.53 Dim.54 Dim.55 Dim.56
## Variance 0.015 0.012 0.011 0.011 0.008 0.008 0.006
## % of var. 0.402 0.323 0.297 0.288 0.218 0.198 0.167
## Cumulative % of var. 98.366 98.688 98.985 99.273 99.491 99.689 99.856
## Dim.57
## Variance 0.005
## % of var. 0.144
## Cumulative % of var. 100.000
##
## Individuals (the 10 first)
## Dim.1 ctr cos2 Dim.2 ctr cos2
## 1 | -0.388 0.026 0.059 | -0.643 0.147 0.163 |
## 2 | 0.520 0.047 0.046 | -0.775 0.214 0.103 |
## 3 | 0.278 0.013 0.008 | -0.113 0.005 0.001 |
## 4 | 0.207 0.007 0.007 | 0.785 0.219 0.105 |
## 5 | 0.320 0.018 0.013 | 0.594 0.126 0.046 |
## 6 | -0.244 0.010 0.017 | -0.592 0.125 0.101 |
## 7 | 0.023 0.000 0.000 | -0.685 0.167 0.068 |
## 8 | 0.048 0.000 0.000 | -0.720 0.185 0.107 |
## 9 | 0.814 0.115 0.106 | -0.250 0.022 0.010 |
## 10 | -0.018 0.000 0.000 | 0.173 0.011 0.011 |
## Dim.3 ctr cos2
## 1 0.289 0.037 0.033 |
## 2 0.088 0.003 0.001 |
## 3 1.262 0.699 0.158 |
## 4 0.316 0.044 0.017 |
## 5 1.063 0.496 0.146 |
## 6 0.782 0.268 0.176 |
## 7 0.889 0.347 0.115 |
## 8 1.206 0.639 0.300 |
## 9 0.884 0.343 0.125 |
## 10 -0.173 0.013 0.011 |
##
## Categories (the 10 first)
## Dim.1 ctr cos2 v.test Dim.2
## LundiTravail_très peu chargé | -0.462 1.645 0.275 -18.080 | -0.552
## LundiTravail_peu chargé | 0.026 0.000 0.000 0.104 | -0.280
## LundiTravail_moyen | 0.541 0.377 0.030 6.008 | -0.031
## LundiTravail_chargé | 0.451 0.312 0.026 5.516 | 0.784
## LundiTravail_très chargé | 0.730 1.585 0.148 13.249 | 1.060
## MardiTravail_très peu chargé | -0.496 1.860 0.303 -18.983 | -0.561
## MardiTravail_peu chargé | 0.747 0.167 0.012 3.849 | -0.620
## MardiTravail_moyen | 0.444 0.324 0.027 5.653 | 0.070
## MardiTravail_chargé | 0.487 0.473 0.040 6.931 | 0.940
## MardiTravail_très chargé | 0.834 1.523 0.132 12.537 | 1.117
## ctr cos2 v.test Dim.3 ctr cos2
## LundiTravail_très peu chargé 4.846 0.393 -21.609 | -0.048 0.045 0.003
## LundiTravail_peu chargé 0.030 0.001 -1.128 | 0.372 0.065 0.002
## LundiTravail_moyen 0.003 0.000 -0.348 | -0.301 0.296 0.009
## LundiTravail_chargé 1.940 0.077 9.584 | 0.228 0.202 0.007
## LundiTravail_très chargé 6.886 0.311 19.233 | 0.114 0.098 0.004
## MardiTravail_très peu chargé 4.916 0.389 -21.497 | -0.069 0.093 0.006
## MardiTravail_peu chargé 0.238 0.009 -3.197 | -0.034 0.001 0.000
## MardiTravail_moyen 0.017 0.001 0.897 | -0.045 0.009 0.000
## MardiTravail_chargé 3.631 0.150 13.370 | 0.353 0.632 0.021
## MardiTravail_très chargé 5.628 0.237 16.785 | -0.043 0.010 0.000
## v.test
## LundiTravail_très peu chargé -1.870 |
## LundiTravail_peu chargé 1.496 |
## LundiTravail_moyen -3.341 |
## LundiTravail_chargé 2.787 |
## LundiTravail_très chargé 2.068 |
## MardiTravail_très peu chargé -2.661 |
## MardiTravail_peu chargé -0.174 |
## MardiTravail_moyen -0.575 |
## MardiTravail_chargé 5.025 |
## MardiTravail_très chargé -0.645 |
##
## Categorical variables (eta2)
## Dim.1 Dim.2 Dim.3
## LundiTravail | 0.286 0.485 0.020 |
## MardiTravail | 0.317 0.511 0.021 |
## MercrediTravail | 0.284 0.494 0.031 |
## JeudiTravail | 0.263 0.490 0.037 |
## VendrediTravail | 0.334 0.445 0.036 |
## SamediTravail | 0.670 0.007 0.286 |
## DimancheTravail | 0.617 0.007 0.209 |
## LundiRepos | 0.628 0.054 0.239 |
## MardiRepos | 0.540 0.251 0.292 |
## MercrediRepos | 0.552 0.240 0.309 |
fviz_screeplot(res.mca)
# fviz_mca_var(res.mca, choice="var")
# fviz_mca_biplot(res.mca, repel=FALSE, ggtheme = theme_minimal(),label="")
# library(ade4)
#
# load_quali$bonus = as.factor(load_quali$bonus)
# acm = dudi.acm(load_quali, scannf = FALSE, nf = 5)
#
# couleurs <- rep("blue", length(acm$li)) # Initialisez toutes les couleurs avec "blue"
#
# # Définissez les couleurs spécifiques pour les points que vous souhaitez changer
# couleurs[1] <- "red" # Par exemple, les points 1, 3 et 5 seront en rouge
#
# # Affichez la visualisation en spécifiant les couleurs
# fviz_mca_var(acm,, repel=TRUE, labelsize = 2)
# couleurs_bonus <- ifelse(load_quali$bonus == "colline", "blue", "red") # Définir les couleurs en fonction des modalités
#
# # Visualiser les colonnes de l'ACM en fonction de la variable bonus
# fviz_ca_col(acm$li)#, col.col = couleurs_bonus)
# fviz_mca_biplot(acm$li, col.var = couleurs_bonus)
# # Initialiser une liste pour stocker les tables de contingence
# contingency_tables <- list()
#
# # Itérer à travers chaque colonne du dataframe
# for (col in names(load_quali)) {
# # Créer une table de contingence pour la colonne actuelle
# contingency_table <- table(load_quali[[col]])
#
# # Stocker la table de contingence dans la liste
# contingency_tables[[col]] <- contingency_table
# }
#
# # Afficher les tables de contingence
# for (i in seq_along(contingency_tables)) {
# cat("Table de contingence pour la colonne", names(load_quali)[i], ":\n")
# print(contingency_tables[[i]])
# cat("\n")
# }
#
# table(contingency_tables)
# ```
# K-means, silhouette et dendogramme
#### Nombre de cluster idéal :
fviz_nbclust(data_pca,method = 'wss', FUNcluster = kmeans)
fviz_nbclust(data_pca,method = 'silhouette', FUNcluster = kmeans)
Avec une autre fonction :
NbClust(data_pca, method = 'kmeans', index = 'all', max.nc = 10)$Best.nc
## *** : The Hubert index is a graphical method of determining the number of clusters.
## In the plot of Hubert index, we seek a significant knee that corresponds to a
## significant increase of the value of the measure i.e the significant peak in Hubert
## index second differences plot.
##
## *** : The D index is a graphical method of determining the number of clusters.
## In the plot of D index, we seek a significant knee (the significant peak in Dindex
## second differences plot) that corresponds to a significant increase of the value of
## the measure.
##
## *******************************************************************
## * Among all indices:
## * 2 proposed 2 as the best number of clusters
## * 13 proposed 3 as the best number of clusters
## * 4 proposed 4 as the best number of clusters
## * 2 proposed 8 as the best number of clusters
## * 2 proposed 10 as the best number of clusters
##
## ***** Conclusion *****
##
## * According to the majority rule, the best number of clusters is 3
##
##
## *******************************************************************
## KL CH Hartigan CCC Scott Marriot TrCovW
## Number_clusters 4.0000 3.0000 3.0000 8.0000 3.000 4.000000e+00 3
## Value_Index 7.7062 800.2994 229.5418 9.3363 1084.655 3.378622e+20 318445893
## TraceW Friedman Rubin Cindex DB Silhouette Duda
## Number_clusters 3.00 4.0000 4.0000 10.0000 3.000 3.0000 3.0000
## Value_Index 15728.84 3.2354 -0.2628 0.3001 1.055 0.3714 1.0806
## PseudoT2 Beale Ratkowsky Ball PtBiserial Frey McClain
## Number_clusters 3.0000 2.0000 8.0000 3.00 3.0000 1 2.0000
## Value_Index -49.7488 1.1046 0.2271 25118.95 0.6718 NA 0.5612
## Dunn Hubert SDindex Dindex SDbw
## Number_clusters 3.0000 0 3.0000 0 10.0000
## Value_Index 0.0685 0 0.2597 0 0.1832
d = dist(data_pca)
reskmeans3 = kmeans(data_pca,centers = 3)
fviz_cluster(reskmeans3,data = data_pca,labelsize=0,ellipse.type = "norm", axes=c(1,2))
sil = silhouette(reskmeans3$cluster, d)
fviz_silhouette(sil)
## cluster size ave.sil.width
## 1 1 535 0.44
## 2 2 370 0.30
## 3 3 284 0.32
clusters_k3 = reskmeans3$cluster
for (k in 2:10){
km.res = kmeans(data_pca, centers = k, nstart = 25)
sil = silhouette(km.res$cluster, dist(data_pca))
plot(sil, main = paste("Sihouette",k), col = rainbow(length(unique(km.res$cluster))), border = NA)
abline(v = mean(sil[,3]))
}
# Set your Stadia Maps API key
apikey <- "bdfc537c-e86b-4abb-8c63-4cedfa75cadd"
register_stadiamaps(apikey, write = TRUE)
## ℹ Replacing old key (bdfc537c) with new key in C:/Users/damie/Documents/.Renviron
#bbox <- c(left = 24.61, bottom = 59.37, right = 24.94, top = 59.5)
#get_stadiamap(bbox, zoom = 12, maptype = "stamen_toner_lite") %>% ggmap()
qmplot(longitude, latitude,data = coord, maptype = "stamen_toner_lite",color=clusters_k3,) +
labs(title = paste("Clusters")) + scale_color_gradient(low = "blue", high ="green")
## ℹ Using `zoom = 12`
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## Warning in geom_point(`NA` = NULL): Ignoring unknown parameters: `NA`
profile1 = colMeans(loading[which(clusters_k3 == 1),])
profile2 = colMeans(loading[which(clusters_k3 == 2),])
profile3 = colMeans(loading[which(clusters_k3 == 3),])
min_value <- min(c(profile1, profile2, profile3))
max_value <- max(c(profile1, profile2, profile3))
plot(profile1, type = 'l', col = "blue", ylim = c(min_value, max_value))
lines(profile2,type='l', col = "grey")
lines(profile3,type='l', col = "green")
abline(v = days, col="red")
library(leaflet)
num_clusters = 3
pal <- colorRampPalette(c("lightblue", "mediumblue"))(num_clusters)
colors <- colorFactor(palette = pal, domain = unique(clusters_k3))
map <- leaflet(coord) %>%
addProviderTiles(provider = providers$Stadia.AlidadeSmooth,
options = providerTileOptions(apikey = apikey)) %>%
addCircles(lng = ~longitude, lat = ~latitude, color = ~colors(clusters_k3),
opacity = 1, fillOpacity = 0.8, radius = 50) %>%
addLegend("bottomright", pal = colors, values = ~clusters_k3,
title = "3 Clusters ",
opacity = 1)
# Print the map
print(map)
reskmeans4 = kmeans(data_pca,centers = 4)
fviz_cluster(reskmeans4,data = data_scale,labelsize=0,ellipse.type = "norm", axes=c(1,2))
sil = silhouette(reskmeans4$cluster,d)
fviz_silhouette(sil)
## cluster size ave.sil.width
## 1 1 279 0.29
## 2 2 236 0.33
## 3 3 249 0.23
## 4 4 425 0.45
clusters_k4 = reskmeans4$cluster
# Set your Stadia Maps API key
apikey <- "bdfc537c-e86b-4abb-8c63-4cedfa75cadd"
register_stadiamaps(apikey, write = TRUE)
## ℹ Replacing old key (bdfc537c) with new key in C:/Users/damie/Documents/.Renviron
#bbox <- c(left = 24.61, bottom = 59.37, right = 24.94, top = 59.5)
#get_stadiamap(bbox, zoom = 12, maptype = "stamen_toner_lite") %>% ggmap()
qmplot(longitude, latitude,data = coord, maptype = "stamen_toner_lite",color=clusters_k4,) +
labs(title = paste("Clusters")) + scale_color_gradient(low = "blue", high ="green")
## ℹ Using `zoom = 12`
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## Warning in geom_point(`NA` = NULL): Ignoring unknown parameters: `NA`
profile1 = colMeans(loading[which(clusters_k4 == 1),])
profile2 = colMeans(loading[which(clusters_k4 == 2),])
profile3 = colMeans(loading[which(clusters_k4 == 3),])
profile4 = colMeans(loading[which(clusters_k4 == 4),])
min_value <- min(c(profile1, profile2, profile3, profile4))
max_value <- max(c(profile1, profile2, profile3, profile4))
plot(profile1, type = 'l', col = "blue", ylim = c(min_value, max_value))
lines(profile2,type='l', col = "purple")
lines(profile3,type='l', col = "darkgreen")
lines(profile4,type='l', col = "green")
abline(v = days, col="red")
Globalement, les clusters 2 et 3 semblent avoir des comportements
similaires en semaine.
# Set your Stadia Maps API key
apikey <- "bdfc537c-e86b-4abb-8c63-4cedfa75cadd"
num_clusters = 4
pal <- colorRampPalette(c("lightblue", "mediumblue", "darkblue"))(num_clusters)
colors <- colorFactor(palette = pal, domain = unique(clusters_k4))
map <- leaflet(coord) %>%
addProviderTiles(provider = providers$Stadia.AlidadeSmooth,
options = providerTileOptions(apikey = apikey)) %>%
addCircles(lng = ~longitude, lat = ~latitude, color = ~colors(clusters_k4),
opacity = 1, fillOpacity = 0.8, radius = 50) %>%
addLegend("bottomright", pal = colors, values = ~clusters_k4,
title = "Clusters",
opacity = 1)
# Print the map
print(map)
Commentaire : Chaque cluster n’a pas une zone géographique propre, on constate néammoins plusieurs tendances se dessiner : Le cluster 1 est présent surtout au centre de Paris (ile de la Cité et alentours). Le cluster 4 correspond surtout aux arrondissement 15, 11, 12. Les clusters 3 et 2 semblent confondus.
gmm_model <- Mclust(data_pca,G=1:6)
summary(gmm_model)
## ----------------------------------------------------
## Gaussian finite mixture model fitted by EM algorithm
## ----------------------------------------------------
##
## Mclust VVE (ellipsoidal, equal orientation) model with 6 components:
##
## log-likelihood n df BIC ICL
## -15422.66 1189 75 -31376.39 -31653.34
##
## Clustering table:
## 1 2 3 4 5 6
## 238 138 178 308 145 182
print(paste("Nombre de clusters optimal",gmm_model$G))
## [1] "Nombre de clusters optimal 6"
gmm_model$BIC
## Bayesian Information Criterion (BIC):
## EII VII EEI VEI EVI VVI EEE
## 1 -36193.27 -36193.27 -33297.06 -33297.06 -33297.06 -33297.06 -33367.87
## 2 -34770.18 -34237.91 -33341.10 -32538.69 -33084.04 -32436.26 -33408.21
## 3 -34340.87 -33702.14 -32958.01 -32297.19 -32825.75 -32229.62 -32923.85
## 4 -32957.13 -32593.26 -32673.59 -31965.62 -32563.92 -31934.89 -32518.02
## 5 -32708.93 -32337.89 -32463.01 -31871.10 -32335.73 -31842.18 -32312.83
## 6 -32562.56 -32291.06 -32238.38 -31694.84 -32179.83 -31751.77 -32295.28
## VEE EVE VVE EEV VEV EVV VVV
## 1 -33367.87 -33367.87 -33367.87 -33367.87 -33367.87 -33367.87 -33367.87
## 2 -32570.59 -32836.52 -32427.45 -32959.02 -32351.43 -32953.99 -32320.24
## 3 -32249.27 -32717.79 -32152.65 -32686.90 -32172.30 -32585.97 -32160.49
## 4 -32004.61 -32371.32 -31881.85 -32321.62 -31899.82 -32233.46 -31886.29
## 5 -31869.80 -32331.33 -31653.14 -32090.04 -31700.81 -32169.34 -31689.22
## 6 -31668.95 -32043.67 -31376.39 -32040.85 -31555.65 -32104.62 -31595.25
##
## Top 3 models based on the BIC criterion:
## VVE,6 VEV,6 VVV,6
## -31376.39 -31555.65 -31595.25
resBIC = Mclust(data_pca,G=2:30, modelNames = "VVE")
summary(resBIC)
## ----------------------------------------------------
## Gaussian finite mixture model fitted by EM algorithm
## ----------------------------------------------------
##
## Mclust VVE (ellipsoidal, equal orientation) model with 10 components:
##
## log-likelihood n df BIC ICL
## -15229.9 1189 119 -31302.42 -31650.64
##
## Clustering table:
## 1 2 3 4 5 6 7 8 9 10
## 165 132 165 30 103 218 80 131 40 125
# Get the cluster assignments
#cluster_assignments <- predict(gmm_model)$classification
# Visualize the results
#plot(loading, col = cluster_assignments, main = "GMM Clustering Results")
#points(gmm_model$parameters$mean, col = 1:3, pch = 8, cex = 2)
#fviz_mclust(gmm_model, labelsize = 0)
#fviz_cluster(gmm_clust,data = data_scale,labelsize=0,ellipse.type = "norm", axes=c(1,2))
ggplot(as.data.frame(data_pca), aes(x = pca$ind$coord[,1], y = pca$ind$coord[,2], color = as.factor(gmm_model$classification))) +
geom_point() +
scale_color_discrete(name = "Cluster") +
labs(x = paste("Composante principale 1",substr(pca$eig[1],1,5),"%"), y = paste("Composante principale 2", substr(pca$eig[2],1,5),"%")) +
theme_minimal()
clusters_gmm = gmm_model$classification
#
# profile1 = colMeans(loading[which(clusters_gmm == 1),])
# profile2 = colMeans(loading[which(clusters_gmm == 2),])
# profile3 = colMeans(loading[which(clusters_gmm == 3),])
# profile4 = colMeans(loading[which(clusters_gmm == 4),])
# profile5 = colMeans(loading[which(clusters_gmm == 5),])
# profile6 = colMeans(loading[which(clusters_gmm == 6),])
#
# profiles_gmm = cbind(profile1,profile2,profile3,profile4, profile5,profile6)
#
# corrplot(cor(profiles_gmm),method = "ellipse")
#
# max(cor(profiles_gmm))
#resICLall = Mclust(loading[!duplicated(rownames(data)), ], G=2:6)
#summary(resICLall)
#fviz_mclust(resICLall,data=data_pca,labelsize= 0)
#
# resICLall = Mclust(data_pca)
# summary(resICLall)
# fviz_mclust(resICLall, data=data_pca, labelsize=0)
#
# clusters_ICL = resICLall$classification
gmm_model4 = Mclust(data_pca,G=4, modelNames = "VVE")
summary(gmm_model4)
## ----------------------------------------------------
## Gaussian finite mixture model fitted by EM algorithm
## ----------------------------------------------------
##
## Mclust VVE (ellipsoidal, equal orientation) model with 4 components:
##
## log-likelihood n df BIC ICL
## -15753.28 1189 53 -31881.85 -32068.87
##
## Clustering table:
## 1 2 3 4
## 241 611 137 200
clusters_gmm4 = gmm_model4$classification
hclustsingle = hclust(d, method="single")
hclustcomplete = hclust(d, method="complete")
hclustaverage = hclust(d, method="average")
hclustward = hclust(d, method="ward.D")
# Dendograms visualization
#fviz_dend(hclustsingle)
#fviz_dend(hclustcomplete)
#fviz_dend(hclustaverage)
#fviz_dend(hclustward)
plot(as.dendrogram(hclustsingle), main = "Single")
plot(as.dendrogram(hclustcomplete), main = "Complete")
plot(as.dendrogram(hclustaverage), main = "Average")
plot(as.dendrogram(hclustward), main = "Ward")
reshclust = cutree(hclustward, 3)
fviz_dend(hclustward, k=3, show_labels=FALSE, rect=TRUE)
## Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
## of ggplot2 3.3.4.
## ℹ The deprecated feature was likely used in the factoextra package.
## Please report the issue at <https://github.com/kassambara/factoextra/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
clusters_cah = unname(reshclust)
# Set your Stadia Maps API key
apikey <- "bdfc537c-e86b-4abb-8c63-4cedfa75cadd"
register_stadiamaps(apikey, write = TRUE)
## ℹ Replacing old key (bdfc537c) with new key in C:/Users/damie/Documents/.Renviron
#bbox <- c(left = 24.61, bottom = 59.37, right = 24.94, top = 59.5)
#get_stadiamap(bbox, zoom = 12, maptype = "stamen_toner_lite") %>% ggmap()
qmplot(longitude, latitude,data = coord, maptype = "stamen_toner_lite",color=clusters_cah,) +
labs(title = paste("Clusters")) + scale_color_gradient(low = "blue", high ="green")
## ℹ Using `zoom = 12`
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## Warning in geom_point(`NA` = NULL): Ignoring unknown parameters: `NA`
profile1 = colMeans(loading[which(clusters_cah == 1),])
profile2 = colMeans(loading[which(clusters_cah == 2),])
profile3 = colMeans(loading[which(clusters_cah == 3),])
min_value <- min(c(profile1, profile2, profile3))
max_value <- max(c(profile1, profile2, profile3))
plot(profile1, type = 'l', col = "blue", ylim = c(min_value, max_value), xlab = "Heures", ylab = "Chargement moyen")
lines(profile2,type='l', col = "grey")
lines(profile3,type='l', col = "green")
abline(v = days, col="red")
#Clusters vs type of stations (hill or not)
tbl = table(coord$bonus, clusters_k3)
print(tbl)
## clusters_k3
## 1 2 3
## 0 413 367 282
## 1 122 3 2
mosaicplot(tbl, color = c(3:5))
Les stations situées en hauteurs appartiennent quasiment toutes au même cluster (clusters obtenus via kmeans).
Map avec différentes méthodes de clusters :
confusionMatrix(as.factor(clusters_k3), as.factor(clusters_cah))
## Confusion Matrix and Statistics
##
## Reference
## Prediction 1 2 3
## 1 489 36 10
## 2 6 348 16
## 3 5 47 232
##
## Overall Statistics
##
## Accuracy : 0.8991
## 95% CI : (0.8805, 0.9156)
## No Information Rate : 0.4205
## P-Value [Acc > NIR] : < 2.2e-16
##
## Kappa : 0.8438
##
## Mcnemar's Test P-Value : 2.384e-08
##
## Statistics by Class:
##
## Class: 1 Class: 2 Class: 3
## Sensitivity 0.9780 0.8074 0.8992
## Specificity 0.9332 0.9710 0.9441
## Pos Pred Value 0.9140 0.9405 0.8169
## Neg Pred Value 0.9832 0.8987 0.9713
## Prevalence 0.4205 0.3625 0.2170
## Detection Rate 0.4113 0.2927 0.1951
## Detection Prevalence 0.4500 0.3112 0.2389
## Balanced Accuracy 0.9556 0.8892 0.9217
confusionMatrix(as.factor(clusters_k3), as.factor(reshclust))
## Confusion Matrix and Statistics
##
## Reference
## Prediction 1 2 3
## 1 489 36 10
## 2 6 348 16
## 3 5 47 232
##
## Overall Statistics
##
## Accuracy : 0.8991
## 95% CI : (0.8805, 0.9156)
## No Information Rate : 0.4205
## P-Value [Acc > NIR] : < 2.2e-16
##
## Kappa : 0.8438
##
## Mcnemar's Test P-Value : 2.384e-08
##
## Statistics by Class:
##
## Class: 1 Class: 2 Class: 3
## Sensitivity 0.9780 0.8074 0.8992
## Specificity 0.9332 0.9710 0.9441
## Pos Pred Value 0.9140 0.9405 0.8169
## Neg Pred Value 0.9832 0.8987 0.9713
## Prevalence 0.4205 0.3625 0.2170
## Detection Rate 0.4113 0.2927 0.1951
## Detection Prevalence 0.4500 0.3112 0.2389
## Balanced Accuracy 0.9556 0.8892 0.9217
confusionMatrix(as.factor(clusters_k4), as.factor(clusters_gmm4))
## Confusion Matrix and Statistics
##
## Reference
## Prediction 1 2 3 4
## 1 0 169 110 0
## 2 0 236 0 0
## 3 119 130 0 0
## 4 122 76 27 200
##
## Overall Statistics
##
## Accuracy : 0.3667
## 95% CI : (0.3392, 0.3948)
## No Information Rate : 0.5139
## P-Value [Acc > NIR] : 1
##
## Kappa : 0.1734
##
## Mcnemar's Test P-Value : <2e-16
##
## Statistics by Class:
##
## Class: 1 Class: 2 Class: 3 Class: 4
## Sensitivity 0.0000 0.3863 0.0000 1.0000
## Specificity 0.7057 1.0000 0.7633 0.7725
## Pos Pred Value 0.0000 1.0000 0.0000 0.4706
## Neg Pred Value 0.7352 0.6065 0.8543 1.0000
## Prevalence 0.2027 0.5139 0.1152 0.1682
## Detection Rate 0.0000 0.1985 0.0000 0.1682
## Detection Prevalence 0.2347 0.1985 0.2094 0.3574
## Balanced Accuracy 0.3528 0.6931 0.3817 0.8862
On constate que les clusters trouvés avec les différentes classifications ne sont pas ordonnés de la même manière. ON propose alors un fonction pour les réordonner :
clusterRearrange <- function(classif1, classif2) {
confMatrix <- table(classif1, classif2)
listMax <- apply(confMatrix, 2, which.max)
confMatrix2 <- matrix(0, nrow = nrow(confMatrix), ncol = ncol(confMatrix))
for (i in 1:length(listMax)) {
confMatrix2[i, ] <- confMatrix[listMax[i], ]
}
classIndices <- numeric(length(classif2))
for (i in 1:length(classif2)) {
for (j in 1:nrow(confMatrix)) {
if (classif2[i] == j) {
classIndices[i] <- listMax[j]
break
}
}
}
classif2_rearranged <- classif2
for (i in 1:length(classif2)) {
classif2_rearranged[i] = classIndices[i]
}
return(classif2_rearranged)
}
Cette fonction renvoie un vecteur identique au deuxième cluster passé en paramètres mais réarrangé suivant le premier.
#
reshclust_rearranged = clusterRearrange(clusters_k3, reshclust)
# confusionMatrix(as.factor(clusters_k3), as.factor(reshclust_rearranged))
clusters_gmm4_rearranged = clusterRearrange(clusters_k4, clusters_gmm4)
#confusionMatrix(as.factor(clusters_k4),as.factor(clusters_gmm4_rearranged))
# Set your Stadia Maps API key
apikey <- "bdfc537c-e86b-4abb-8c63-4cedfa75cadd"
register_stadiamaps(apikey, write = TRUE)
## ℹ Replacing old key (bdfc537c) with new key in C:/Users/damie/Documents/.Renviron
#bbox <- c(left = 24.61, bottom = 59.37, right = 24.94, top = 59.5)
#get_stadiamap(bbox, zoom = 12, maptype = "stamen_toner_lite") %>% ggmap()
qmplot(longitude, latitude,data = coord, maptype = "stamen_toner_lite",color=clusters_k3,) +
labs(title = paste("Clusters with k-means (3 clusters)")) + scale_color_gradient(name = "Clusters",low = "blue", high ="green")
## ℹ Using `zoom = 12`
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## Warning in geom_point(`NA` = NULL): Ignoring unknown parameters: `NA`
qmplot(longitude, latitude,data = coord, maptype = "stamen_toner_lite",color=clusters_k4,) +
labs(title = paste("Clusters with k-means (4 clusters)")) + scale_color_gradient(name = "Clusters",low = "blue", high ="green")
## ℹ Using `zoom = 12`
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## Warning in geom_point(`NA` = NULL): Ignoring unknown parameters: `NA`
qmplot(longitude, latitude,data = coord, maptype = "stamen_toner_lite",color=clusters_cah,) +
labs(title = paste("Clusters with CAH (3 clusters)")) + scale_color_gradient(name = "Clusters",low = "blue", high ="green")
## ℹ Using `zoom = 12`
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## Warning in geom_point(`NA` = NULL): Ignoring unknown parameters: `NA`
qmplot(longitude, latitude,data = coord, maptype = "stamen_toner_lite",color=clusters_gmm,) +
labs(title = paste("Clusters with GMM (6 clusters)")) + scale_color_gradient(name = "Clusters",low = "blue", high ="green")
## ℹ Using `zoom = 12`
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## Warning in geom_point(`NA` = NULL): Ignoring unknown parameters: `NA`
qmplot(longitude, latitude,data = coord, maptype = "stamen_toner_lite",color=clusters_gmm4,) +
labs(title = paste("Clusters with GMM (4 clusters)")) + scale_color_gradient(name = "Clusters",low = "blue", high ="green")
## ℹ Using `zoom = 12`
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## Warning in geom_point(`NA` = NULL): Ignoring unknown parameters: `NA`